﻿using System;
using System.Diagnostics;

namespace msBsc.SvRef
{
    public class SysProcessm
    {

        /// <summary>
        /// 停止进程
        /// </summary>
        /// <param name="processName">进程名称</param>
        /// <param name="beforeStartTime">进程启动前的时间</param>
        /// <param name="afterStartTime">里程启动后的时间</param>
        /// <remarks></remarks>
        public static void Kill(string processName, DateTime beforeStartTime, DateTime afterStartTime)
        {

            Process[] mProcessList;
            DateTime mProcessStartTime;

            mProcessList = Process.GetProcessesByName(processName);

            foreach (Process tmpProcess in mProcessList)
            {
                mProcessStartTime = tmpProcess.StartTime;
                if (mProcessStartTime.CompareTo(beforeStartTime) > 0 && mProcessStartTime.CompareTo(afterStartTime) < 0)
                //if (mProcessStartTime > beforeStartTime && mProcessStartTime < afterStartTime)
                {
                    tmpProcess.Kill();
                }
            }

        }
    }
}
